home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / halcn305.zip / GSDMO_09.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-02  |  3KB  |  113 lines

  1. program GSDMO_09;
  2. {------------------------------------------------------------------------------
  3.                               DBase Index Creator
  4.  
  5.        Copyright (c)  Richard F. Griffin
  6.  
  7.        20 January 1993
  8.  
  9.        102 Molded Stone Pl
  10.        Warner Robins, GA  31088
  11.  
  12.        -------------------------------------------------------------
  13.        Unit to demonstrate more complex index processing.
  14.  
  15.        The GSDMO_09.DBF file will be created, if it does not exist, by
  16.        using the MakeTestData procedure in GSOB_GEN.PAS.
  17.  
  18.        The IndexOn routine will be used to index on LASTNAME.  This can
  19.        be commented out after the index is created and just  use the
  20.        index by the command: Index('GSDMO_09').
  21.  
  22.        The indexed file will be listed ascending and descending.
  23.  
  24.        Finally, Find is called using the LASTNAME in physical record
  25.        35.  The record number of the first occurrence of the name will
  26.        be returned.  This may be record 35, or an earlier record if one
  27.        exists with the same last name.
  28.  
  29.        New procedures/functions introduced are:
  30.  
  31.                  dBOF
  32.                  Find
  33.                  GoBottom
  34.                  TrimR
  35.  
  36. -------------------------------------------------------------------------------}
  37.  
  38. uses
  39.    GSOB_Gen,
  40.    GSOB_Str,
  41.    GSOBShel,
  42.    {$IFDEF WINDOWS}
  43.       WinCRT,
  44.       WinDOS;
  45.    {$ELSE}
  46.       CRT,
  47.       DOS;
  48.    {$ENDIF}
  49.  
  50. var
  51.    s       : string;
  52.    li      : boolean;
  53.    i       : integer;
  54.    oi      : integer;
  55.    c       : char;
  56.    ms      : string[30];
  57. begin
  58.    ClrScr;
  59.  
  60.    if not FileExist('GSDMO_09.DBF') then
  61.    begin
  62.       writeln('Creating GSDMO_09.DBF');
  63.       MakeTestData(3,'GSDMO_09', 50, false);
  64.       writeln('GSDMO_09.DBF Created');
  65.    end;
  66.  
  67.    Select(1);
  68.    Use('GSDMO_09');
  69.    IndexOn('GSDMO_09','LASTNAME');
  70.  
  71.    i := 0;
  72.    GoTop;
  73.    while (not dEOF) do
  74.    begin
  75.       inc(i);
  76.       if (i mod 23) = 0 then
  77.       begin
  78.          write('Press any key to continue.');
  79.          c := ReadKey;
  80.          writeln;
  81.       end;
  82.       s := FieldGet('LASTNAME');
  83.       writeln(RecNo:8,'   ',s,i:6);    {Write the record number}
  84.       Skip(1);
  85.    end;
  86.    writeln('End of Ascending check, Now for descending...');
  87.    writeln('Press any key to continue.');
  88.    c := ReadKey;
  89.    i := 0;
  90.  
  91.    GoBottom;                   {Now get the last record in the file}
  92.    while (not dBOF) do         {Repeat until at the beginning of file}
  93.    begin
  94.       inc(i);
  95.       if (i mod 23) = 0 then
  96.       begin
  97.          write('Press any key to continue.');
  98.          c := ReadKey;
  99.          writeln;
  100.       end;
  101.       s := FieldGet('LASTNAME');
  102.       writeln(RecNo:8,'   ',s,i:6);
  103.       if RecNo = 35 then ms := s;
  104.       Skip(-1);                 {Resd the previous record}
  105.    end;
  106.  
  107.    ms := TrimR(ms);
  108.    Find(ms);
  109.    writeln('The first record for ',ms,' is ',RecNo);
  110.    CloseDataBases;
  111. end.
  112.  
  113.